﻿using System;
using System.Collections.Generic;
using System.Web;

namespace IService.Utility
{
	public class SessionState
	{
		static readonly string userId = "currentUser";

		static T GetSessionState<T>(string index)
		{
			return (T)HttpContext.Current.Session[index];
		}

		static T GetSessionState<T>(string index, object defaultValue)
		{
			return HttpContext.Current.Session[index] == null ? (T)defaultValue : (T)HttpContext.Current.Session[index];
		}

		static void SetSessionState(string index, object value)
		{
			HttpContext.Current.Session[index] = value;
		}

		public static void ClearSession()
		{
			HttpContext.Current.Session.Clear();
			// HttpContext.Current.Session.Abandon();
		}

		public static Model.User CurrentUser
		{
			get { return GetSessionState<Model.User>(userId, new Model.User()); }
			set { SetSessionState(userId, value); }
		}
	}
}